package ma.co.ba.BusinessApplications.presentation.controllers.listes;

import java.util.List;

import ma.co.ba.BusinessApplications.business.commons.CommonBusiness;
import ma.co.ba.BusinessApplications.business.tickets.TicketBusiness;
import ma.co.ba.BusinessApplications.business.utilisateurs.UtilisateurBusiness;
import ma.co.ba.BusinessApplications.model.Criticite;
import ma.co.ba.BusinessApplications.model.Utilisateur;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/criticites")
public class CriticiteController {
	@Autowired
	UtilisateurBusiness utilisateurBusiness;
	@Autowired
	TicketBusiness ticketBusiness;
	@Autowired
	CommonBusiness commonBusiness;

	@RequestMapping(method = RequestMethod.GET)
	public String listesPage(ModelMap model) {
		return "criticites";
	}

	@RequestMapping(method = RequestMethod.POST)
	public String processOnSubmit(@ModelAttribute("newCriticite") Criticite newCriticite, ModelMap model) {
		
		commonBusiness.saveEntity(newCriticite);
		return "redirect:/criticites";
	}

	@ModelAttribute("newCriticite")
	public Criticite getNewCriticite() {
		return new Criticite();
	}

	

	@ModelAttribute("criticitesList")
	public List<Criticite> getCriticitesList() {
		return ticketBusiness.getAllCriticites();
	}

	
	@ModelAttribute("utilisateurs")
	public List<Utilisateur> getUtilisateurs() {
		List<Utilisateur> utilisateurs = utilisateurBusiness
				.getAllConsultants();
		return utilisateurs;
	}
}
